﻿
using System;
using System.Collections.Generic;
using System.Text;

namespace FundHelper.Model
{
    public class FundHisBase
    {
        public string? id { get; set; }
        public string? date { get; set; }
        public string dwjz{ get; set; }
        public double zzl { get; set; }
        public double low { get; set; }
        public double high { get; set; }
        public FundHisBase() {
            dwjz = "0";
        }
        // 显式转换运算符
        public static explicit operator FundHistory(FundHisBase a)
        {
            bool dateOk = DateTime.TryParse(a.date, out var d);
            string dwjz= a.dwjz.Replace(",", "");
            if (dateOk)
            {
                return new FundHistory
                {
                    id = a.id,
                    dwjz = double.Parse(a.dwjz),
                    zzl = a.zzl,
                    date = d,
                    high = a.high,
                    low = a.low
                };
            }
            else
            {
                return new FundHistory
                {
                    id = a.id,
                    dwjz = double.Parse(a.dwjz),
                    zzl = a.zzl,
                    high = a.high,
                    low = a.low
                };
            }
        }
    }
    public class FundHistory:ICloneable, ICanToTuple
    {
        public string? id { get; set; }
        public string? function_id { get; set; }
        public DateTime date { get; set; }
        public double dwjz { get; set; }
        public double high { get; set; }
        public double low { get; set; }


        public double ljjz { get; set; }

        public double zzl { get; set; }

        public double BIAS5 { get; set; }
        public double BIAS10 { get; set; }
        public double BIAS20 { get; set; }
        public double MA5 { get; set; }
        public double MA10 { get; set; }
        public double MA20 { get; set; }
        public double EMA9 { get; set; }
        public double EMA12 { get; set; }
        public double EMA26 { get; set; }
        public double MACD { get; set; }
        public AF? Af { get; set; }
        
        public object Clone()
        {
            return new FundHistory()
            {
                id = this.id,
                dwjz = this.dwjz,
                zzl = this.zzl,
                date = this.date
            };
        }

        public Quote ToQuote()
        {
            return new Quote()
            {
                Date = date,
                High = high,
                Low = low,
                Name = this.id??"",
                Id = this.function_id??"",
                Price = this.dwjz
            };
        }

        public (DateTime dateTime, double value) ToTuple()
        {
            return (date, dwjz);
        }
    }
}
